/**
 *  timer.c - The timer driver.
 *
 *  Copyright (C) 2008-2010 ZhangHu
 *  All rights reserved.
 *  E-MAIL: anmnmnly@gmail.com
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
#include "drivers/timer.h"
#include "devs.h"


extern void stop_timer(void);
extern void start_timer(void);
extern void change_duty_cycle(timer_duty_cycle_t *arg);
extern void init_timer(void);



static int32 timer_ioctl(uint32 cmd, void *arg)
{
    if((cmd != TIMER_CMD_START) &&
        (cmd != TIMER_CMD_STOP) &&
        (cmd != TIMER_CMD_CHG))
    {
        return(-1);
    }

    switch(cmd) {
        case TIMER_CMD_START:
            start_timer();
            break;

        case TIMER_CMD_STOP:
            stop_timer();
            break;

        case TIMER_CMD_CHG:
            change_duty_cycle((timer_duty_cycle_t*)arg);
            break;
    }

	return(0);
}



struct chdev_operations timer_op = {
    NULL,
    NULL,
    NULL,
    NULL,
    timer_ioctl,
    NULL
};



void timer_register(void)
{
    init_timer();

    chdevRegister(TIMER_ID, TIMER0_ID, TIMER0, 0, &timer_op);
}

